home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_geomview.idb / usr / freeware / lib / geomview / maple / remotegv.z / remotegv
Encoding:
Text File  |  1999-01-26  |  4.5 KB  |  136 lines

  1. #! /bin/sh
  2.  
  3. # Invoke geomview possibly remotely.
  4. # For use within Maple, install this remotegv script somewhere in users'
  5. # search paths (e.g. in /usr/local/bin).
  6. # This script attempts to guess which machine to invoke geomview on by
  7. # examining the DISPLAY environment variable.  If DISPLAY isn't set or
  8. # if geomview should run on a different machine, use the -h host option.
  9. #
  10. # The script also assumes that geomview should display on the machine where
  11. # it is invoked, so for that copy of geomview, it sets DISPLAY to ":0".
  12. # If the display should appear elsewhere (on an X terminal, say),
  13. # use the -display option.
  14. #
  15. # We use "rsh" (remote shell) to pass data to the other computer, so 
  16. # the remote computer must allow this -- either with an entry in
  17. # /etc/hosts.equiv, or in a .rhosts file in the user's home directory
  18. # on the machine where geomview will run.  The account name on the other
  19. # machine is assumed to be the same as on this machine; if different,
  20. # use the -l username or -h username@othermachine options.
  21. #
  22. # In case permissions are not set up correctly, the symptom
  23. # is liable to be a "Permission denied." message followed by the
  24. # immediate termination of the Maple process -- so if you're using it for
  25. # the first time, check it out before doing much else in your Maple session!
  26. # Sorry, but MapleV3 is just not very good at connecting to other programs.
  27. #
  28. # Note that togeomview and geomview MUST BE IN THE USER'S DEFAULT SEARCH PATH
  29. # on the remote machine.
  30. #
  31. # To use this script within Maple, you'd say:
  32. #    readlib(gvplot);
  33. # then
  34. #    gvcommand := `remotegv`;
  35. # or e.g.
  36. #    gvcommand := `remotegv -h othermachine -display myxterm:0`;
  37. # or, if the account on the other machine is different from yours,
  38. #    gvcommand := `remotegv -l otheraccount`;
  39. # or
  40. #    gvcommand := `remotegv -h otheraccount@othermachine`;
  41. # Following any remotegv options, you can add the command to be invoked as
  42. # geomview, possibly including options, as in:
  43. #    gvcommand := `remotegv -l person /u/person/bin/gv -wpos 300x200`;
  44. #
  45. # Then use gvplot() as usual.
  46. #
  47. # Normally, error messages reporting problems on the other machine (for
  48. # example, being unable to run geomview) are suppressed; this is unfortunately
  49. # necessary, or you'd never get another Maple prompt until quitting from
  50. # geomview.  There's a test mode to aid in tracing problems; use it as in
  51. #    gvcommand := `remotegv -test -h othermachine`;
  52. # i.e. add "-test" to whatever other options you'd give to remotegv.
  53. # Option summary:
  54. # -l user  or  -l user@host
  55. # -h host  or  -h user@host
  56. # -display host:number        (set display on remote end)
  57. # -test
  58. # also accepts togeomview's options (-g, -M[c][g][p][s]).
  59.  
  60. # Invokes rsh to specified machine, invokes togeomview there by default.
  61. #
  62. # By default, we assume DISPLAY points to the machine where we'd like to be;
  63. #   -h {host-portion-of-DISPLAY} -display :0
  64. # Incorporates settings from "$RGVOPTS" environment variable.
  65.  
  66. set -- $RGVOPTS "$@"
  67.  
  68. while
  69.   case "$1" in
  70.   -l)
  71.     case "$2" in
  72.     *@*) user="`expr match "$2" '\([^@]*\)'`"
  73.          host="`expr match "$2" '.*@\(.*\)'`" ;;
  74.     *) user="$2" ;;
  75.     esac
  76.     shift 2 ;;
  77.  
  78.   -h)   case "$2" in
  79.     *@*) user="`expr match "$2" '\([^@]*\)'`"
  80.          host="`expr match "$2" '.*@\(.*\)'`" ;;
  81.     *) host="$2" ;;
  82.     esac
  83.     shift 2 ;;
  84.  
  85.   -test) testopt=-test; shift ;;
  86.   -display) rdisplay="$2"; shift 2 ;;
  87.   -M*) togvopts="$togvopts $1";
  88.      inpipe="$2"
  89.      shift 2 ;;
  90.   -g)  gopt=-g; shift ;;
  91.   "") test ;;
  92.   *) togvargs="$togvargs $1"; shift ;;
  93.   esac
  94. do :
  95. done
  96.  
  97. # Apply defaults
  98.  
  99. if [ -z "$host" ]; then
  100.   host="`expr match "$DISPLAY" '\([^:]*\)'`"
  101. fi
  102.  
  103. if [ -z "$rdisplay" ]; then
  104.   rdisplay=":0.0"
  105. fi
  106.  
  107. case "$inpipe" in
  108.   /*) ;;
  109.   ?*) inpipe=/tmp/geomview/$inpipe ;;
  110. esac
  111.  
  112. user=${user+"-l $user"}
  113. cmd="${host+rsh $host $user}"
  114.  
  115. if [ -n "$host" ]; then
  116.   redirect=">/dev/null 2>&1"
  117.   if [ -n "$testopt" ]; then
  118.     echo "Testing setup to $host.  If geomview or togeomview can't be started
  119. there, you should see messages explaining why.  Unfortunately this command
  120. may not finish on its own -- you may need to interrupt (perhaps with control-C)
  121. after seeing the results, before you get another Maple prompt." >&2
  122.     redirect=""
  123.   fi
  124.   if [ -n "$inpipe" ]; then
  125.     rsh $host $user sh -c "\"DISPLAY=$rdisplay togeomview $gopt ${togvopts} $inpipe $togvargs $redirect\"" <$inpipe
  126.   else
  127.     rsh $host $user sh -c "\"DISPLAY=$rdisplay togeomview $gopt ${togvopts} $togvargs $redirect\""
  128.   fi
  129. else
  130.   case "$1" in
  131.     ""|-*) DISPLAY=$rdisplay geomview ${togvopts} $togvargs ;;
  132.     *) DISPLAY=$rdisplay ${togvopts} $togvargs;;
  133.   esac
  134. fi
  135.